'''
元素等待的3种方法：
(1)显式等待是针对某一个元素进行相关等待判定；
①WebDriverWait()
(2)隐式等待不针对某一个元素进行等待，全局元素等待。
①implicitly_wait()	默认参数的单位为秒。
(3)sleep休眠方法
①sleep()
'''
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
# from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC  # 起个别名
from time import sleep
from options import options

driver = webdriver.Chrome(options=options)
driver.get(r'https://www.baidu.com/')
driver.maximize_window()
driver.implicitly_wait(30)  # 隐式等待，单位为秒
sleep(3)

driver.find_element(By.ID, 'kw').send_keys('aaaa')

# 针对百度按钮进行显式等待
su_loc = (By.ID, 'su')
ele = WebDriverWait(driver, 30, 0.5).until(EC.visibility_of_element_located(su_loc))  # 是否可见
# WebDriverWait(driver,30,0.5).until(EC.presence_of_element_located(su_loc)) # 是否存在
ele.click()
sleep(3)  # 死等

driver.quit()
